/**
 * 课程相关API接口
 */
import { get, post, put } from '@/utils/request.js'

/**
 * 获取课程列表
 * @param {Object} params - 查询参数
 * @param {number} params.page - 页码
 * @param {number} params.size - 每页数量
 * @param {string} params.keyword - 搜索关键词
 * @param {string} params.category - 分类
 * @param {string} params.sort - 排序方式
 */
export const getCourseList = (params = {}) => {
  return get('/courses', params)
}

/**
 * 获取课程详情
 * @param {string} id - 课程ID
 */
export const getCourseDetail = (id) => {
  return get(`/courses/${id}`)
}

/**
 * 获取课程章节
 * @param {string} courseId - 课程ID
 */
export const getCourseChapters = (courseId) => {
  return get(`/courses/${courseId}/chapters`)
}

/**
 * 获取推荐课程
 */
export const getRecommendedCourses = () => {
  return get('/courses/recommended')
}

/**
 * 获取热门课程
 */
export const getPopularCourses = () => {
  return get('/courses/popular')
}

/**
 * 搜索课程
 * @param {string} keyword - 搜索关键词
 */
export const searchCourses = (keyword) => {
  return get('/courses/search', { keyword })
}

/**
 * 获取课程分类
 */
export const getCategories = () => {
  return get('/categories')
}

/**
 * 获取课程评论
 * @param {string} courseId - 课程ID
 */
export const getCourseComments = (courseId) => {
  return get(`/courses/${courseId}/comments`)
}

/**
 * 添加课程评论
 * @param {Object} data - 评论数据
 */
export const addComment = (data) => {
  return post('/comments', data)
}

/**
 * 收藏课程
 * @param {string} courseId - 课程ID
 */
export const favoriteCourse = (courseId) => {
  return post(`/courses/${courseId}/favorite`)
}

/**
 * 取消收藏课程
 * @param {string} courseId - 课程ID
 */
export const unfavoriteCourse = (courseId) => {
  return del(`/courses/${courseId}/favorite`)
}

/**
 * 获取收藏的课程
 */
export const getFavoriteCourses = () => {
  return get('/courses/favorites')
}

/**
 * 更新学习进度
 * @param {Object} data - 进度数据
 */
export const updateProgress = (data) => {
  return post('/learning/progress', data)
}

/**
 * 获取学习进度
 * @param {string} courseId - 课程ID
 */
export const getProgress = (courseId) => {
  return get(`/learning/progress/${courseId}`)
}

export default {
  getCourseList,
  getCourseDetail,
  getCourseChapters,
  getRecommendedCourses,
  getPopularCourses,
  searchCourses,
  getCategories,
  getCourseComments,
  addComment,
  favoriteCourse,
  unfavoriteCourse,
  getFavoriteCourses,
  updateProgress,
  getProgress
}